#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h> 
#include <stdlib.h> 
#include <string.h> 
#include <math.h> 
#include <ctype.h> 
#include <time.h> 
#include <assert.h>

typedef long long LL;
LL f[300000] = { 0 };

int main()
{
	int n = 0;
	scanf("%d", &n);

	for (int i = 1; i <= n; i++)
	{
		LL x = 0;
		scanf("%lld", &x);
		f[i] = f[i - 1] + x;
	}

	LL ret = -1e10;
	LL premin = 0;
	for (int i = 1; i <= n; i++)
	{
		ret = ret > f[i] - premin ? ret : f[i] - premin;
		premin = premin < f[i] ? premin : f[i];
	}

	printf("%lld\n", ret);
	return 0;
}
